<template>
	<view id="contianer">
		<view>
			<view class="title">当前密码</view>
			<view style="display: flex; width: 100%;" class="input">
				<input placeholder="请输入当前密码" placeholder-style="font-size:26rpx;color:#ACACAC;" type="password" name="input" v-model="password" />
			</view>
		</view>
		<view>
			<view class="title">新的密码</view>
			<view class="input">
				<input placeholder="请输入新的密码" placeholder-style="font-size:26rpx;color:#ACACAC;" type="password" name="input" v-model="newPassword" />
			</view>
		</view>
		<view>
			<view class="title">确认密码</view>
			<view class="input">
				<input placeholder="请确认新的密码" placeholder-style="font-size:26rpx;color:#ACACAC;" type="password" name="input" v-model="confirmPassword" />
			</view>
		</view>
		
		<view style="margin-top: 60rpx;">
				<button class="button" @click="update()">确认修改</button>	
		</view>
	</view>
</template>

  
</view>
<script>
import axios from 'axios';
import config from '../../common/config';
  export default {
    data() {
      return {
		  password:'',
		  newPassword:'',
		  confirmPassword:'',
		  loginForm:{
			ghId:uni.getStorageSync('ghId'),
			ghPwd:uni.getStorageSync('pwd')+""
		},
		code:0
      };
    }
	,
	
	created() {
		let id=uni.getStorageSync('ghId')
	},
	methods:{
		
		
		
		update(){
			
			uni.setStorageSync('pwd',this.newPassword)
			let pwd=uni.getStorageSync('ghPwd')
			
			 if(this.password.length==0){
				 uni.showToast({
				 	title:'当前密码不能为空',
					icon:'error'
				 })
			 }else if(pwd!=this.password &&this.password!=null){
				uni.showToast({
				title:"当前密码错误",
				icon:'error'
				
				})
	    	}else if (pwd=this.password && this.newPassword.length==0 || this.confirmPassword.length==0){
				uni.showToast({
					title:'新密码不能为空',
					icon:'error'
					
				})
			}else if(pwd=this.password && this.newPassword.length<6 || this.newPassword.length>12){
				uni.showToast({
					title:'新密码不合法',
					icon:'error'
					
				})
			}else if(pwd=this.password && this.confirmPassword.length<6 || this.confirmPassword.length>12){
				uni.showToast({
					title:'新密码不合法'
				})
			}else if(pwd=this.password&& this.newPassword!=this.confirmPassword){
				uni.showToast({
					title:'密码不一致',
					icon:'error'
					
				})
			}else if(pwd=this.password && this.newPassword==this.confirmPassword && this.confirmPassword.length!=0){
				axios.put(config.baseUrl+'supplier/ssmsupplier/updateSecret/',this.loginForm)
				.then((response)=>{
					this.code=response.data.code
					console.log(this.code)			
					if(this.code==0){
						uni.reLaunch({
							url:'/pages/denglu/denglu'
						})
					}

					
				})
			
			
			}
			
		},
	}
}		
</script>

<style scoped>
	page{
	  height:100%
	}
	#contianer {
		padding-top: 1rpx;
		position: relative;
		height: 100%;
		/* 本页面背景颜色 */
		background-color: #F5F5F5;
	}
	.title {
		color: #696969;
		margin: 15rpx 20rpx;
	}
	.input {
		padding: 20rpx 20rpx;
		background-color: #fff;
	}
	.button {
		width: 93%;
		color: #fff;
		background-color: #00BFFF;
	}
</style>

